<html xmlns:th="http://www.thymeleaf.org"
	  th:with="ctx=${#httpServletRequest.contextPath}"
> 
<head>
</head>
<script type="text/javascript" src="js/jqurey.js"></script>
<body onload="check()">
<div>
<div>
    <button onclick="changePermission()">用户权限管理</button>
    <li id="select" onclick="selectOne()" style="display: none;">查询用户</li>
    <li id="add" onclick="addOne()" style="display: none;">添加用户</li>
    <li  id="delete" onclick="deleteOne()" style="display: none;">删除用户</li>
    <li id="update" onclick="updateOne()" style="display: none;">修改用户</li>
    <li id="login" onclick="login()" style="display: none;">用户登录</li>
    <li id="submit" onclick="submited()" style="display: none;">用户注册</li>
</div>
    
</div>
<script>
    function selectOne() {
        window.location.href="page/selectOne"
    }

    function addOne() {
        window.location.href="page/addOne"
    }

    function deleteOne() {
        window.location.href="page/deleteOne"
    }

    function updateOne() {
        window.location.href="page/updateOne"
    }

    function login() {
        window.location.href= "login"
    }

    function submited() {
        window.location.href= "page/submit"
    }

    function changePermission() {
        window.location.href="page/change"
    }

    /**
     * 判断数组中是否有某元素
     * @param arr
     * @param obj
     * @returns {boolean}
     */
    function contains(arr, obj) {
        var i = arr.length;
        while (i--) {
            if (arr[i] === obj) {
                return true;
            }
        }
        return false;
    }


    function check(){
        var data = localStorage.getItem("data");
        var arr = JSON.parse(data).permission;
        console.log(arr);

        if(contains(arr, "user.add")){
            document.getElementById("add").style.display="block";
        }
        if(contains(arr,"user.delete")){
            document.getElementById("delete").style.display="block";
        }
        if(contains(arr,"user.update")){
            document.getElementById("update").style.display="block";
        }
        if(contains(arr,"user.select")){
            document.getElementById("select").style.display="block";
        }
        if(contains(arr,"user.login")){
            document.getElementById("login").style.display="block";
        }
        if(contains(arr,"user.submit")){
            document.getElementById("submit").style.display="block";
        }
    }
</script>

</body>
</html>